<?php
// +----------------------------------------------------------------------
// | Fengli [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://www.yanyongwang.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 风黎 < 1280246895@qq.com >
// +----------------------------------------------------------------------


namespace app\admin\model;

use \think\Model;
class Article extends Model
{
    //是否开启自动格式化时间戳
    protected $dateFormat = false;
	public function cate()
    {
        //关联分类表
        return $this->belongsTo('ArticleCate');
    }

    public function admin()
    {
        //关联角色表
        return $this->belongsTo('Admin');
    }

    //默认需要执行的查询条件
    public function defaultWhere()
    {
        //不查询 状态为4 的内容  已删除
        $this->where('status','neq','4');
        return $this;
    }

    //格式化时间
    public function formatTime($article,$rule)
    {
        foreach ($article as $k=> $v)
        {
            $article[$k]['create_time'] = is_string($v['create_time']) ? date($rule,strtotime($v['create_time'])) : date($rule,$v['create_time']);
            $article[$k]['update_time'] = is_string($v['update_time']) ? date($rule,strtotime($v['update_time'])) : date($rule,$v['update_time']);
        }

        return $article;
    }
}
